<?php
$folder='others';
$table;
$type;
if(isset($_GET['type'])){
    $type = $_GET['type'];
switch ($_GET['type']) {
    case '1':
        $folder='chatPng';
        $table = 'huabu_messages';
        break;
    case '2':
         $folder = 'channel';
         $table ='channel';
        break;
    case '3':
          $folder = 'geolocation';
        break;
    case '4':
           $folder = 'treehole';
           $table = 'treehole';
        break;
    case '5':
     $folder = 'friend';
     $table = 'friend';
        break;
    case '6':
     $folder = 'treehole';
     $table = 'treehole';
        break;
    default:
        // code...
        break;
}}

$fileToPath = "{$folder}/{$_FILES["image"]["name"]}";
$fileFromPath = $_FILES["image"]["tmp_name"];
if($_FILES["image"]["error"]===UPLOAD_ERR_OK){
    //echo "UPLOAD_ERR_OK";
    if($_FILES["image"]["size"]<10485760){
        //echo "image size";
        if(exif_imagetype($fileFromPath)==IMAGETYPE_PNG){
            //echo "exif_imagetype";
        move_uploaded_file($fileFromPath,$fileToPath);
       }
    }
}
if(isset($_GET['tid'])){
    $tid =$_GET['tid'];
    $servername = "localhost";
    $username = "root";
    $password = "123456";
    $dbname = "huayuan";
// 创建连接
$conn = new mysqli($servername, $username, $password,$dbname);
         
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
} 
    $date = time();
   // $t = date_timestamp_get($date);
    $sql = "UPDATE $table SET send_time =? WHERE huabu_id =?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("is", $t, $tid);
    $stmt->execute();
    if($stmt->affected_rows==0 && $type=='1'){
        $conn->query("INSERT INTO huabu_messages(huabu_id,send_time)
        VALUES ($tid,$date)");
    }
    echo $date;
}
?>